package server;

import java.util.HashMap;
import java.util.Iterator;

public class TimeMap {
	long creatTime;
	HashMap<CleanTaskIdent, ?> cleanTaskTable;
	@SuppressWarnings("unchecked")
	TimeMap(long creatTime){
		this.creatTime=creatTime;
		cleanTaskTable=new HashMap();
	}
	
	void cleanAll(){
		Iterator<CleanTaskIdent> it=cleanTaskTable.keySet().iterator();
		while(it.hasNext()){
			CleanTaskIdent cti=it.next();
			CleanTask ct=server.Config.cleanTaskMange.getCleanTask(cti);
			if(ct!=null){
				Node node=server.Config.nodeMange.getRandomSNode();
				if(node!=null){
					node.runCleanTask(ct);
				}
				ct.runCount--;
				if(ct.runCount==0){
					server.Config.cleanTaskMange.removeCleanTask(cti);
				}
			}
		}
	}
	
	void addCleanTask(CleanTaskIdent cti){
		cleanTaskTable.put(cti, null);
	}
	
	void removeCleanTask(CleanTaskIdent cti){
		cleanTaskTable.remove(cti);
	}
	
	boolean containsCleanTask(CleanTaskIdent cti){
		return cleanTaskTable.containsKey(cti);
	}
	
	
}
